<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/static/h-ui/lib/Hui-iconfont/1.0.8/iconfont.css" />

    <script type="text/javascript" src="/static/h-ui/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/h-ui/lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="/static/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="/static/h-ui/js/H-ui.admin.page.js"></script>
</head>

<body>
    <div class="cl pd-5 bg-1 bk-gray">
        <a href="{:url('/file_manager/selectpicture')}" class="btn btn-default radius sethumb">
            <i class="Hui-iconfont">&#xe600;</i> 站内选择 </a>&nbsp;&nbsp;
        <a href="javascript:void(0);" class="btn btn-primary radius sethumb">
            <i class="Hui-iconfont">&#xe600;</i> 本地上传 </a>&nbsp;&nbsp;
        <a href="{:url('/file_manager/onlinepicture')}" class="btn btn-default radius sethumb">
            <i class="Hui-iconfont">&#xe600;</i> 网络图片 </a>&nbsp;&nbsp;
    </div>
    <!-- 本地上传 -->
    <div class="step1 active" style="margin-left:30px;">
        <form id="submit_form" method="post" action="" enctype="multipart/form-data">
            <input type="hidden" name="isthumb" id="isthumb" value="1">
            <div class="row cl" style="margin-top:20px;">
                <label class="form-label col-xs-2 col-sm-2">
                    <span class="c-red">*</span>本地上传：</label>
                <div class="formControls col-xs-6 col-sm-6">
                    <input type="file" class="input-text" name="image" id="upload_file">
                </div>
                <!-- <input type="text" name="test_text" id="test_text" value="test"> -->
                <div class="col-3"> </div>
            </div>
            <div class="row cl" style="margin-top:20px;">
                <label class="form-label col-xs-2 col-sm-2">生成缩略图：</label>
                <div class="formControls col-xs-6 col-sm-6">
                    <div class="radio-box">
                        <input name="isthumb" type="radio" id="isthumb-1" value="0" checked>
                        <label for="sex-1">否</label>
                    </div>
                    <div class="radio-box">
                        <input name="isthumb" type="radio" id="isthumb-2" value="1">
                        <label for="sex-2">是</label>
                    </div>
                </div>
            </div>
            <div class="row cl" style="margin-top:20px;">
                <label class="form-label col-xs-2 col-sm-2">保留原文件名：</label>
                <div class="formControls col-xs-6 col-sm-6">
                    <div class="radio-box">
                        <input name="formername" type="radio" id="sex-2" value="0" checked>
                        <label for="sex-2">否</label>
                    </div>
                    <div class="radio-box">
                        <input name="formername" type="radio" id="sex-1" value="1">
                        <label for="sex-1">是</label>
                    </div>
                </div>
            </div>
            <div class="row cl" style="margin-top:30px;margin-left:30px;">
                <div class="col-xs-6 col-sm-5 col-xs-offset-2 col-sm-offset-2">
                    <input class="btn btn-primary radius" type="button" value="&nbsp;确&nbsp;定&nbsp;" onCLick="uploadThumb()">
                    <input class="btn btn-default radius" type="button" value="&nbsp;取&nbsp;消&nbsp;" onClick="layer_close();">
                </div>
            </div>
        </form>
    </div>
    <!-- 本地上传end -->

<script type="text/javascript" src="/static/js/jquery.form.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">

    //step1本地上传图片
    function uploadThumb() {
        if ($("#upload_file").val() == '') {
            layer.msg("请选择要上传的文件", {
                icon: 6,
                time: 1000
            });
            return false;
        } else {
            var formData = new FormData($("#submit_form")[0]);
            var isthumb = $('input:radio[name="isthumb"]:checked').val()
            // console.log(formData);
            //ajax上传
            $.ajax({
                url: '{:url("/file_manager/upload")}',
                type: 'POST',
                async: true,
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                beforeSend: function () {
                    uploading = true;
                },
                success: function (data) {
                    if (data.code == 2) {
                        // console.log(data.thumbname);
                        // console.log(data.filename);
                        var imgname = '';
                        if (isthumb==1) {
                            imgname = '/upload/' + data.thumbname;
                        } else {
                            imgname = '/upload/' + data.filename;
                        }

                        window.parent.$("#showthumb").attr('src',imgname);
                        window.parent.$("#thumb").val(imgname);
                        layer_close();
                    } else {
                        layer.msg(data.msg, {
                            icon: 5,
                            time: 1000
                        });
                        return false;
                    }
                    uploading = false;
                }
            });
        }
    }
</script>
<!--请在上方写此页面业务相关的脚本-->

</body>

</html>